<template>
  <div>
    <a-card :bordered="false">
      <f-search-form @searchHandler="searchHandler">
        <f-search-form-item label="用户名" name="userName"/>
        <f-search-form-item label="企业账户" name="account"/>
        <f-search-form-item label="用户状态" name="status" type="select" :data="api.common.userStatus"></f-search-form-item>
        <f-search-form-item label="手机号" name="mobile" slot="advanced"/>
        <f-search-form-item label="注册日期" name="rangeDate" type="range" slot="advanced"/>
      </f-search-form>
      <f-table ref="table" size="default" rowKey="userId" handler="userListHandler" :columns="columns" :operator="operator" :params="queryParam" :api="api.appuser">
        <span slot="status" slot-scope="text, record, index">
          <a-switch v-model="record.status==1" checkedChildren="启用" unCheckedChildren="禁用" @change="setStatus(record)"/>
        </span>
        <span slot="avatar" slot-scope="text, record, index">
          <img :src="record.avatar" alt="" width="40" height="40" class="radius-img">
        </span>
        <span slot="sexSlot" slot-scope="text, record, index">
          <a-tag>{{dictFormat('sex',text)}}</a-tag>
        </span>

        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="$refs.modal.handleShow(record)">编辑</a>
            <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="$refs.table.remove(record.userId)">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </f-table>
    </a-card>
    <user-modal ref="modal"></user-modal>
  </div>
</template>

<script>
  import UserModal from './user_modal'

  export default {
    name: 'TableList',
    components: {
      UserModal
    },
    data () {
      return {
        //列表初始化查询参数
        queryParam: {},
        // 表头
        columns: [
          {
            title: '头像',
            align: 'center',
            dataIndex: 'avatar',
            scopedSlots: { customRender: 'avatar' }
          },
          {
            title: '企业名称',
            align: 'center',
            dataIndex: 'companyName'
          },
          {
            title: '企业账户',
            align: 'center',
            dataIndex: 'account'
          },
          {
            title: '用户名',
            align: 'center',
            dataIndex: 'userName'
          },
          {
            title: '性别',
            align: 'center',
            dataIndex: 'sex',
            scopedSlots: { customRender: 'sexSlot' }
          },
          {
            title: '城市',
            align: 'center',
            dataIndex: 'areaName'
          },
          {
            title: '邮箱',
            align: 'center',
            dataIndex: 'email',
            sorter: true,
            customRender: (text) => text
          },
          {
            title: '手机号',
            align: 'center',
            dataIndex: 'mobile'
          },
          {
            title: '状态',
            align: 'center',
            dataIndex: 'status',
            sorter: true,
            scopedSlots: { customRender: 'status' }
          },
          {
            title: '创建日期',
            align: 'center',
            dataIndex: 'createTime',

            sorter: true
          },
          {
            title: '操作',
            align: 'center',
            dataIndex: 'action',
            width: '200px',
            scopedSlots: { customRender: 'action' }
          }
        ],
        //操作按钮
        operator: [

          {
            name: '删除',
            icon: 'delete',
            batch: true,
            handler: function (table) {
              table.remove()
            }
          }
        ]
      }
    },
    created () {

    },
    methods: {
      setStatus (record) {
        this.http.post(this, {
          url: this.api.appuser.setStatus,
          data: {
            userId: record.userId
          },
          success (me, data) {
            record.status = data
          }
        })
      }
    }
  }
</script>
